package com.bigger.arch.app.customer.client.Impl;

import com.bigger.arch.app.customer.client.IHelloClient;
import com.bigger.arch.app.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Service
public class HttpClientImpl implements IHelloClient {

    @Autowired
    RestTemplate restTemplate;

    public String sayHello(String name) {

        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        return restTemplate.getForEntity("http://bigger-app-service/hello/sayHello?name={name}", String.class, params).getBody();

    }

    public UserDto saveUser(UserDto userDto) {

        Map<String, Object> params = new HashMap<>();

        //post contentType 默认是以application-json请求的
        UserDto body = restTemplate.postForEntity("http://bigger-app-service/hello/saveUser", userDto, UserDto.class, params).getBody();
        return body;
    }
}
